{% extends "admin/models/base_filters.html" %}

{% block main_menu %}
{% endblock %}

{% block custom_bar %}
{% endblock %}

{% block sidebar %}
<h3>最新上架</h3>
<ul id="nav" class="nav nav-list">
		{% for new in new_list %}
			<li><a href="#">{{ new.title|fix_underscores }}</a></li>
		{% endfor %}
</ul>
<br/>
<h3>Top 10</h3>
<ul id="nav" class="nav nav-list">
		{% for top in top_list %}
			<li><a href="#">{{ top.title|fix_underscores }}</a></li>
		{% endfor %}
</ul>
{% endblock %}

{% block content_title %}{% endblock %}

{% block breadcrumb %}
<ul class="breadcrumb">
	<li><span class="divider"></span></li>
</ul>
{% endblock %}

{% block pre_content %}
  <ul class="nav nav-tabs">
    <li class="{% block tab_index_class %}active{% endblock %}"><a href="/?{{ request.query_string }}">{{ model_admin.get_display_name()|fix_underscores }} ({{ model_admin.get_query().count() }})</a></li>
{% macro list_fields(node, prefix) %}
  {% for field in node.fields %}
    <li><a
        class="field-filter"
        data-field="{{ field.name|apply_prefix(prefix, 'fv_') }}"
        data-select="{{ field.name|apply_prefix(prefix, 'fo_') }}"
        id="filter-{{ field.name|apply_prefix(prefix, 'fo_') }}"
        href="#">{% if prefix %}{{ ' / '.join(prefix) }} / {% endif %}{% if field.verbose_name %}{{ field.verbose_name }}{% else %}{{field.name}}{% endif %}</a>
    </li>
  {% endfor %}
{% endmacro %}
    <li class="dropdown" style="float:right">
      <a class="dropdown-toggle" data-toggle="dropdown" href="#">搜索... <span class="caret" /></a>
      <ul class="dropdown-menu pull-right" id="filters">
        {{ list_fields(field_tree, []) }}
      </ul>
    </li>
  </ul>
{% endblock %}



{% block content %}
  {% include "admin/includes/filter_widgets.html" %}

  <form action="." class="form-horizontal" id="model-list" method="post"><input type="hidden" name="action" value="" />
  <table class="table table-bordered table-striped">
    <thead>
      <tr>
        {% if model_admin.columns or model_admin.show_all_columns %}
          {% for column in model_admin.columns or model_admin.get_columns() %}
            {% if ordering == column %}
              {% set sort_by = '-'+column %}
            {% else %}
              {% set sort_by = column %}
            {% endif %}
            <th>{% if model_admin.column_is_sortable(column) %}<a href="./?{{ update_querystring(request.query_string, 'ordering', sort_by)|safe() }}">{% endif %}{{ model_admin.get_column_display(column) }}{% if model_admin.column_is_sortable(column) %}</a>{% endif %}</th>
          {% endfor %}
        {% else %}
          <th>{{ model_admin.get_display_name() }}</th>
        {% endif %}
		{% if model_admin.get_primary_key() %}
        <th class="last shrink"></th>
		{% endif %}
      </tr>
    </thead>
    <tbody>
    {% for object in query.get_list() %}
      <tr>
        {% if model_admin.columns or model_admin.show_all_columns %}
          {% for column in model_admin.columns or model_admin.get_columns()  %}
            {% if loop.index == 1 %}
			  {% if model_admin.get_primary_key() %}
              <td><a href="">{{ get_model_field(object, column) }}</a></td>
			  {% else %}
			  <td>{{ get_model_field(object, column) }}</td>
			  {% endif %}
            {% else %}
              <td>{{ get_model_field(object, column) }}</td>
            {% endif %}
          {% endfor %}
        {% else %}
          <td><a href="{{ url_for(model_admin.get_url_name('edit'), pk=object.get_id()) }}">{{ object }}</a></td>
        {% endif %}
		{% if model_admin.get_primary_key() %}
        <td class="last links">
          <ul class="inline">
          	{% if object.owned %}
            <li><a href="{{ url_for(model_admin.get_url_name('revert'), pk=object.get_id()) }}">还书</a></li>
			{% else %}
            <li><a href="{{ url_for(model_admin.get_url_name('borrow'), pk=object.get_id()) }}">借阅</a></li>
			 {% endif %}
          </ul>
        </td>
		{% endif %}
      </tr>
    {% endfor %}
    </tbody>
  </table>
  </form>
  {% include "admin/includes/pagination.html" %}
{% endblock %}
